// packageB/pages/package/liangdeng/bind_positon/bind_positon.js
const mybehavior = require("../../../../../../behaviors/requests")
import Dialog from '@vant/weapp/dialog/dialog';
Page({

  /**
   * 页面的初始数据 
   */
  behaviors: [mybehavior],
  data: {
    baseUrl: "https://logisticsengineering.gree.com/order_system",
    status_style_none: "margin-top: 20rpx;color: red;",
    status_style_done: "margin-top: 20rpx;color:#07c160",
    page_size: 10,
    page: 1,
    total: 0,
    page_all: 0,
    inspect_time: "",
    abnormal:"--",
    inspecting:"--",
    total_time:"--",
  },
  // 分页
  onPageChange(e) {
    // console.log("xxx",e.detail.sonParam);
    let p = e.detail.sonParam
    this.setData({
      page: p,
    })
    this.seeCheckRes()
  },

  // 查询检测结果
  seeCheckRes() {
    wx.showLoading({
      title: '获取数据中',
    })
    let url = this.data.baseUrl + "/get_hardware_status"
    let data = {
      page_size: this.data.page_size,
      page: this.data.page,
    }
    // console.log(data);


    this.post(url, data).then(res => {

      if (res.code == 20000) {
        let time = this.GMTToStr(res.data.results[0].inspect_time)

        this.setData({
          list: res.data.results,
          page_all: Math.ceil(res.data.total / this.data.page_size),
          total: res.data.total,
          abnormal: res.data.abnormal,
          inspecting: res.data.inspecting,
          total_time: res.data.total_time,
          inspect_time: time
        })
        wx.hideLoading()

      } else {
        wx.showToast({
          title: res.msg,
          icon: 'error'
        })
      }
    }).catch(err => {
      console.log(err);
      wx.showToast({
        title: err.msg,
        icon: 'none'
      })
    })
  },
  // 导出数据
  downFile() {
    wx.downloadFile({
      url: 'https://logisticsengineering.gree.com/order_system/get_hardware_status_xlsx',
      filePath: wx.env.USER_DATA_PATH + '/' + '检测标签结果.xlsx',
      header:{
        Authorization:wx.getStorageSync('token')
      },
      success: function (res) {
        console.log(res)
        const filePath = res.filePath;
        wx.openDocument({
          filePath: filePath,
          showMenu: true,
          fileType: 'xlsx',
          success: function (res) {
            console.log('打开文档成功', res)
          }
        })
      },
      fail: function (err) {
        console.log(err)
      }
    })
  },
  /*
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

    this.seeCheckRes()

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})